package com.example.cat.chinagirl918.WidgetManger;

import android.appwidget.AppWidgetManager;
import android.content.ComponentName;
import android.content.Context;
import android.graphics.Bitmap;
import android.widget.RemoteViews;

import com.example.cat.chinagirl918.R;
import com.example.cat.chinagirl918.Server.MyApplication;

/**
 * Created by cat on 2018/4/30.
 */

public class WidgetHelper {
    /**
     * 更新选择界面的图片
     *
     * @param bitmap
     */
    public static void UpdateView(Bitmap bitmap) {

        ComponentName componentName = new
                ComponentName(MyApplication.getContext()
                , NewAppWidget.class);
        RemoteViews remoteViews = new RemoteViews(MyApplication.getContext().getPackageName(), R.layout.new_app_widget);
        remoteViews.setImageViewBitmap(R.id.widget_img, bitmap);
        UpdateWidget(MyApplication.getContext(), componentName, remoteViews);

    }

    /**
     * 更新widget，处理相关信息
     *
     * @param context
     * @param componentName
     * @param remoteViews
     */
    public static void UpdateWidget(Context context, ComponentName componentName, RemoteViews remoteViews) {
        //由AppWidgetManager处理Wiget。
        AppWidgetManager awm = AppWidgetManager.getInstance(context);
        awm.updateAppWidget(componentName, remoteViews);
    }
}
